Skip to main content

Overview

The server package provides the SSH server that handles client connections and manages Bubble Tea sessions for the Duet TUI.

Types

Server

Main server struct that manages SSH connections and room state.

Functions

New

Creates a new Duet server instance.
string
required
The address to listen on (e.g., “localhost:2222”)
string
required
Path to the SSH host key file
string
Optional URL for the AI worker service. If empty, AI features will be disabled
Returns: A configured *Server instance Example:

Start

Starts the SSH server and blocks until shutdown.
Returns: Error if the server fails to start or during shutdown Example:
Behavior:
  • Starts SSH server with Bubble Tea middleware
  • Listens for OS interrupt signals (SIGINT, SIGTERM)
  • Performs graceful shutdown with 10-second timeout
  • Logs server lifecycle events

Implementation Details

SSH Middleware

The server uses Wish middleware for SSH handling:
  • Bubble Tea Middleware: Manages TUI sessions
  • Logging Middleware: Logs connection events

Session Handling

Each SSH connection:
  1. Extracts username (defaults to “guest”)
  2. Creates a Bubble Tea renderer
  3. Detects terminal type (special handling for xterm-ghostty)
  4. Initializes a UI model with the room manager
  5. Launches in alternate screen mode

Color Profile Detection

The server automatically enables TrueColor for Ghostty terminal.